<?php

function hubungan_get_statuses($before,$after,$follow) {
	$where = '';
	$sort = 'DESC';
	if ($before != -1) {
		$sort = 'DESC';
		$where = ' AND stat_id < '.$before.' ';
	} elseif ($after != -1) {
		$sort = 'ASC';
		$where = ' AND stat_id > '.$after.' ';
	}
	$statuses = db_array('SELECT stat_id,stat_date,stat_txt,reply_stat,restat_from,user_id,username,name FROM status INNER JOIN users ON stat_user = user_id WHERE (stat_user = 0 '.$follow.') '.$where.' ORDER BY stat_id '.$sort.' LIMIT 0,11'); // equal 11 okay to more
	if ($sort == 'ASC') {
		$statuses = array_reverse($statuses);
	}
	return extend_statuses($statuses);
}

if (defined('NO_DIRECT')) {
	$following = get_followings($session['user']['user_id']);
	$where = '';
	foreach ($following['list'] as $a) {
		$where .= ' OR stat_user = '.$a['user_who'];
	}
	if (isset($_GET['before'])) {
		$statuses = hubungan_get_statuses(intval($_GET['before']),-1,$where);
	} elseif (isset($_GET['after'])) {
		$statuses = hubungan_get_statuses(-1,intval($_GET['after']),$where);
	} else {
		$statuses = hubungan_get_statuses(-1,-1,$where);
	}
	if (isset($_GET['ajax'])) {
		header('Content-type: text/plain');
		echo json_encode($statuses);
	} else {
		$post = get_posts($session['user']['user_id']);
		$follower = get_followers($session['user']['user_id']);
		foreach ($statuses as $a) {
			echo '<p><strong>@'.$a['username'].'</strong><br />'.show_status($a['stat_txt']).'<br />'.$a['stat_date'].'</p>';
		}
	}
}
